import Vue from 'vue'
import VueRouter from 'vue-router'

import {
	getItem
} from '@/utils/storage.js'

import index from '../views/index.vue'
import personal from '@/views/personal.vue'
import resources from '@/views/resources.vue'
import resoudetails from '@/views/resoudetails.vue'
import maps from '@/views/maps.vue'
import login from '@/views/login.vue'
import ForgetPassword from '@/views/loginInfo/ForgetPassword.vue'
//常
import userAgreement from '@/views/loginInfo/userAgreement.vue' //用户协议
import registerUser from '@/views/loginInfo/registerUser.vue' //注册账号
import ForgetPasswords from '@/views/loginInfo/ForgetPasswords.vue' //账号安全
import backPassword from '@/views/loginInfo/backPassword.vue' //找回密码
//个人中心
import personageInfo from '@/views/personage/personageInfo.vue' //个人信息
import feedback from '@/views/personage/feedback.vue' //意见反馈
import department from '@/views/personage/department.vue' //部门管理
import auditAdmin from '@/views/personage/auditAdmin.vue' //审核管理-管理
import auditAdminSubmit from '@/views/personage/auditAdminSubmit.vue' //审核管理-提交
import toAuditFlow from '@/views/personage/toAuditFlow.vue' //审核管理-提交
import dxandtj from '@/views/personage/dxandtj.vue' //地学和图鉴
import personalDataFile from '@/views/personage/dataFile.vue' //资料档案

//钻孔
import drillAdmin from '@/views/drill/drillAdmin.vue' ////钻孔管理
import addDrill from '@/views/drill/addDrill.vue' ////新增钻孔
import drillDetails from '@/views/drill/drillDetails.vue' ////钻孔详情
//下载中心
import download from '@/views/download/index.vue' ////钻孔详情
//城市地质
import geologyCity from '@/views/geologyCity/index.vue' //城市地质首页
import details from '@/views/geologyCity/details.vue' //详情
import fileDetail from '@/views/geologyCity/fileDetail.vue' //文件
import articleDetail from '@/views/geologyCity/articleDetail.vue' //文件
import article from '@/views/geologyCity/subjectClassify/article.vue' //文章
import subjectClassifyDrill from '@/views/geologyCity/subjectClassify/drill.vue' //钻孔
import file from '@/views/geologyCity/subjectClassify/file.vue' //地学产品
import geologyCityHome from '@/views/geologyCity/subjectClassify/home.vue' //地学产品
import mapsFile from '@/views/geologyCity/subjectClassify/mapsFile.vue' //图件
import dataFile from '@/views/geologyCity/subjectClassify/dataFile.vue' //资料档案
import dataFielDetail from '@/views/geologyCity/dataFielDetail.vue' //资料档案-详情
import monitoring from '@/views/geologyCity/subjectClassify/monitoring.vue' //监测点
import geology from '@/views/geologyCity/subjectClassify/geology.vue' //地质科普
import addzlda from '@/views/geologyCity/addzlda.vue' //新增资料档案 
import adddxTj from '@/views/geologyCity/adddxTj.vue' //新增地学
import addTj from '@/views/geologyCity/addTj.vue' //新增和图鉴

//区域海洋
import ocean from '@/views/ocean/index.vue'
import oceanFile from '@/views/ocean/subjectClassify/oceanFile.vue' //地学产品
import oceanArticle from '@/views/ocean/subjectClassify/oceanArticle.vue' //标准规范
import oceanSubjectClassifyDrill from '@/views/ocean/subjectClassify/oceanSubjectClassifyDrill.vue' //钻孔
import oceanHome from '@/views/ocean/subjectClassify/home.vue' //首页
import oceanMapsFile from '@/views/ocean/subjectClassify/oceanMapsFile.vue' //图件
import oceanDataFile from '@/views/ocean/subjectClassify/oceanDataFile.vue' //资料档案
import oceanMonitoring from '@/views/ocean/subjectClassify/oceanMonitoring.vue' //监测点
//地热资源
import geothermy from '@/views/geothermy/index.vue'
import geothermyFile from '@/views/geothermy/subjectClassify/geothermyFile.vue' //地学产品
import geothermyArticle from '@/views/geothermy/subjectClassify/geothermyArticle.vue' //标准规范
import geothermySubjectClassifyDrill from '@/views/geothermy/subjectClassify/geothermySubjectClassifyDrill.vue' //钻孔
import geothermyHome from '@/views/geothermy/subjectClassify/home.vue' //首页
import geothermyMapsFile from '@/views/geothermy/subjectClassify/geothermyMapsFile.vue' //图件
import geothermyMonitoring from '@/views/geothermy/subjectClassify/geothermyMonitoring.vue' //监测点
import geothermyDataFile from '@/views/geothermy/subjectClassify/geothermyDataFile.vue' //资料档案
//实时通讯
import realTime from '@/views/realTime/index.vue'
import realTimeDetails from '@/views/realTime/realTimeDetails.vue'

import monster from '@/views/monster.vue'
import notFind from '@/views/notFind.vue'
import dwd from '@/views/dwd.vue'



Vue.use(VueRouter)


const routes = [{
		path: '/',
		redirect: index
	},
	{
		path: '/monster',
		name: 'monster',
		component: monster
	}, {
		path: '/dwd',
		name: 'dwd',
		component: dwd
	},
	{
		path: '/index',
		name: 'index',
		component: index
	},
	{
		path: "/resources",
		name: "resources",
		component: resources
	},
	{
		path: "/resoudetails",
		name: "resoudetails",
		component: resoudetails
	},
	{
		path: "/maps",
		name: "maps",
		component: maps
	},
	{
		path: "/personal",
		name: "personal",
		component: personal,
		meta: {
			bread: ["个人中心"]
		},
		children: [{
				path: "/",
				name: "personageInfo",
				component: personageInfo,
				meta: {
					activeMenu: '/personal'
				}
			},
			{
				path: "/feedback",
				name: "feedback",
				component: feedback
			},
			{
				path: "/department",
				name: "department",
				component: department
			},
			{
				path: "/auditAdmin",
				name: "auditAdmin",
				component: auditAdmin
			},
			{
				path: "/dxcp",
				name: "dxcp",
				component: auditAdmin
			},
			{
				path: "/tj",
				name: "/tj",
				component: auditAdmin
			},
			{
				path: "/zlda",
				name: "zlda",
				component: auditAdmin
			},
			{
				path: "/zk",
				name: "zk",
				component: auditAdmin
			},
			{
				path: "/auditAdminSubmit",
				name: "auditAdminSubmit",
				component: auditAdminSubmit
			},
			{
				path: "/toAuditFlow",
				name: "toAuditFlow",
				component: toAuditFlow
			},
			{
				path: "/dxandtj",
				name: "dxandtj",
				// redirect: "/dxandtj",
				component: dxandtj,
			},
			{
				path: "/dxandtjs",
				name: "dxandtjs",
				component: dxandtj,
			},
			{
				path: "/personalDataFile",
				name: "personalDataFile",
				component: personalDataFile
			}
		]
	},
	{
		path: "/login",
		name: "login",
		component: login
	},
	{
		path: "/ForgetPassword",
		name: "ForgetPassword",
		component: ForgetPassword
	},
	{
		path: "/userAgreement",
		name: "userAgreement",
		component: userAgreement
	},
	{
		path: "/registerUser",
		name: "registerUser",
		component: registerUser
	},
	{
		path: "/ForgetPasswords",
		name: "ForgetPasswords",
		component: ForgetPasswords
	},
	{
		path: "/backPassword",
		name: "backPassword",
		component: backPassword
	},
	{
		path: "/drillAdmin",
		name: "drillAdmin",
		component: drillAdmin,
		meta: {
			bread: ["钻孔管理"]
		},
	},
	{
		path: "/addDrill",
		name: "addDrill",
		component: addDrill,
		meta: {
			bread: ["钻孔管理", '新增']
		},
	},
	{
		path: "/drillDetails",
		name: "drillDetails",
		component: drillDetails,
		meta: {
			bread: ["钻孔管理", '钻孔详情']
		},
	},
	{
		path: "/download",
		name: "download",
		component: download,
	},
	{
		path: "/geologyCity",
		name: "geologyCity",
		component: geologyCity,
		meta: {
			bread: ["城市地质"]
		},
		children: [{
				path: "/subjectClassifyDrill",
				name: "subjectClassifyDrill",
				component: subjectClassifyDrill
			},
			{
				path: "/article",
				name: "article",
				component: article
			},
			{
				path: "/file",
				name: "file",
				component: file,
			},
			{
				path: '/',
				name: 'geologyCityHome',
				component: geologyCityHome,
				meta: {
					activeMenu: '/geologyCity'
				}
			},
			{
				path: '/mapsFile',
				name: 'mapsFile',
				component: mapsFile
			},
			{
				path: '/dataFile',
				name: 'dataFile',
				component: dataFile
			},
			{
				path: '/monitoring',
				name: 'monitoring',
				component: monitoring
			}, {
				path: '/geology',
				name: 'geology',
				component: geology
			},
		],
	},
	{
		path: '/details',
		name: 'details',
		component: details,
		meta: {
			bread: ["城市地质", "文章详情"]
		}
	},
	{
		path: '/addzlda',
		name: 'addzlda',
		component: addzlda,
		meta: {
			bread: ["资料档案", "新增"]
		}
	},
	{
		path: '/adddxTj',
		name: 'adddxTj',
		component: adddxTj,
		meta: {
			bread: ["新增"]
		}
	}, {
		path: '/addTj',
		name: 'addTj',
		component: addTj,
		meta: {
			bread: ["新增"]
		}
	},
	{
		path: '/fileDetail',
		name: 'fileDetail',
		component: fileDetail,
		meta: {
			bread: ["城市地质", "详情"]
		}
	}, {
		path: '/dataFielDetail',
		name: 'dataFielDetail',
		component: dataFielDetail,
		meta: {
			bread: ["详情"]
		}
	},
	{
		path: '/articleDetail',
		name: 'articleDetail',
		component: articleDetail,
		meta: {
			bread: ["详情"]
		}
	},
	{
		path: '/ocean',
		name: 'ocean',
		component: ocean,
		meta: {
			bread: ["区域海洋"]
		},
		children: [{
				path: "/oceanSubjectClassifyDrill",
				name: "oceanSubjectClassifyDrill",
				component: oceanSubjectClassifyDrill
			},
			{
				path: "/oceanArticle",
				name: "oceanArticle",
				component: oceanArticle
			},
			{
				path: "/oceanMapsFile",
				name: "oceanMapsFile",
				component: oceanMapsFile
			},
			{
				path: "/oceanDataFile",
				name: "oceanDataFile ",
				component: oceanDataFile
			},
			{
				path: "/oceanMonitoring",
				name: "oceanMonitoring ",
				component: oceanMonitoring
			},
			{
				path: "/",
				name: "oceanHome ",
				component: oceanHome,
				meta: {
					activeMenu: '/ocean'
				}
			},
			{
				path: "/oceanFile",
				name: "oceanFile",
				component: oceanFile
			}
		]
	},
	{
		path: '/geothermy',
		name: 'geothermy',
		component: geothermy,
		meta: {
			bread: ["地热资源"]
		},
		children: [{
				path: "/geothermySubjectClassifyDrill",
				name: "geothermySubjectClassifyDrill",
				component: geothermySubjectClassifyDrill
			},
			{
				path: "/geothermyArticle",
				name: "geothermyArticle",
				component: geothermyArticle
			},
			{
				path: "/geothermyMapsFile",
				name: "geothermyMapsFile",
				component: geothermyMapsFile
			},
			{
				path: "/geothermyDataFile",
				name: "geothermyDataFile",
				component: geothermyDataFile
			},
			{
				path: "/geothermyMonitoring",
				name: "geothermyMonitoring",
				component: geothermyMonitoring
			},
			{
				path: "/",
				name: "geothermyHome",
				component: geothermyHome,
				meta: {
					activeMenu: '/geothermy'
				}
			},
			{
				path: "/geothermyFile",
				name: "geothermyFile",
				component: geothermyFile
			}
		]
	},
	{
		path: '/realTime',
		name: 'realTime',
		component: realTime,
		meta: {
			bread: ["地质科普"]
		}
	},
	{
		path: '/realTimeDetails',
		name: 'realTimeDetails',
		component: realTimeDetails,
		meta: {
			bread: ["地质科普详情"]
		}
	},
	{
		path: '*',
		name: '404',
		component: notFind,
		meta: {
			bread: ['404未找到']
		}
	}
]

const router = new VueRouter({
	// mode: 'history',
	mode: 'hash',
	routes
})

// const originalPush = VueRouter.prototype.push
// VueRouter.prototype.push = function push(location) {
// 	return originalPush.call(this, location).catch(err => err)
// }

//没有登录不可跳转的路由
const whiteList = ['/personal', '/department', '/auditAdmin', '/feedback', '/toAuditFlow']

//加上全局前置导航守卫
router.beforeEach((to, from, next) => {
	if (getItem('token')) {
		next();
	} else {
		// 没有token
		if (whiteList.indexOf(to.path) == -1) {
			// 在免登录白名单，直接进入
			next()
		} else {
			next('/index') // 否则全部重定向到登录页
		}
	}
	// next();
})

export default router
